package main

import (
	"context"
	"dawn/conf"
	"dawn/member"
	"flag"
	"log"
	"time"

	"github.com/smallnest/rpcx/client"
)

func main() {
	flag.Parse()

	d := client.NewZookeeperDiscovery(conf.Conf.RPCBasePath, "UserRPC", []string{conf.Conf.ZkAddr}, nil)
	xclient := client.NewXClient("UserRPC", client.Failtry, client.RandomSelect, d, client.DefaultOption)
	defer xclient.Close()

	args1 := &member.SignupArgs{
		Username: "tom2",
		Password: "123",
		Realname: "张三",
	}

	args2 := &member.LoginArgs{
		Username: "tom5",
		Password: "123",
	}

	reply1 := &member.Reply{}
	err := xclient.Call(context.Background(), "Signup", args1, reply1)
	if err != nil {
		log.Fatalf("failed to call: %v", err)
	}
	log.Printf("reply1 is: %v", reply1)

	for {

		reply2 := &member.Reply{}
		err := xclient.Call(context.Background(), "Login", args2, reply2)
		if err != nil {
			log.Fatalf("failed to call: %v", err)
		}

		log.Printf("%s || %s || %s || %s", args2.Username, args2.Password, reply2.C, reply2.M)
		time.Sleep(1e9)
	}

}
